import requests

# emp 员工的意思
# 定义 员工管理 类
class IhrmEmpApi(object):
    # 定义 添加员工 方法
    @classmethod
    def add_emp(cls, header, req_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers=header, json=req_data)
        return resp

    # 定义 查询员工 方法
    @classmethod
    def query_emp(cls, emp_id, header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/"+emp_id, headers=header)
        return resp

    # 定义 修改员工 方法
    @classmethod
    def modify_emp(cls, emp_id, header, req_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/"+emp_id,
                            headers=header, json=req_data)
        return resp

    # 定义 删除员工 方法
    @classmethod
    def del_emp(cls, emp_id, header):
        return requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/"+emp_id, headers=header)

if __name__ == '__main__':
    req_header = {"Authorization": "ca0da927-ae56-4902-b8ce-78ab8c8b55ad"}
    json = {
        "username": "user87655430",
        "mobile": "13947874780",
        "workNumber": "9527890aa"
    }
    response = IhrmEmpApi.add_emp(req_header, json)
    print("添加员工结果：", response.json())

    response = IhrmEmpApi.query_emp("1494919461403222016", req_header)
    print("查询员工结果：", response.json())

    modify_data = {"username": "放大镜考虑"}
    response = IhrmEmpApi.modify_emp("1494919461403222016", req_header, modify_data)
    print("修改员工结果：", response.json())

    response = IhrmEmpApi.del_emp("1494919461403222016", req_header)
    print("删除员工结果：", response.json())